﻿// ==========================================================================
// SourceFileViewer.cs
// Silverlight Shapes Library
// ==========================================================================
// Copyright (c) Silverlight Shapes Development Group
// All rights reserved.
// ==========================================================================

using System.Windows;
using System.Windows.Controls;

namespace SD.Samples.Views
{
    /// <summary>
    /// Custom control to display some source code.
    /// </summary>
    public partial class SourceFileViewer : UserControl
    {
        #region Dependency Properties

        /// <summary>
        /// Defines the <see cref="Source"/> dependency property.
        /// </summary>
        public static readonly DependencyProperty SourceProperty =
            DependencyProperty.Register("Source", typeof(string), typeof(SourceFileViewer), new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnSourceChanged)));
        /// <summary>
        /// Gets or sets the source file that must be displayed.
        /// </summary>
        /// <value>The source file that must be displayed.</value>
        public string Source
        {
            get { return (string)GetValue(SourceProperty); }
            set { SetValue(SourceProperty, value); }
        }

        private static void OnSourceChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            var owner = o as SourceFileViewer;
            if (owner != null)
            {
                owner.OnSourceChanged();
            }
        }

        private void OnSourceChanged()
        {
            TextBlock.Text = Source;
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="SourceFileViewer"/> class.
        /// </summary>
        public SourceFileViewer()
        {
            InitializeComponent();
        }

        #endregion
    }
}
